﻿using B.S.BaseData.Api.Read.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;
using System.Collections.Generic;

namespace B.S.BaseData.Api.Read.CommandHandler.GoodsCommandHandler
{
    public class GoodsproductsImgShowCommandHandler : IRequestHandler<GoodsproductsImgShowCommand, APIResult<List<ImgInfo>>>
    {
        private readonly IBaseRepository<ImgInfo> _ImgRepository;
        public GoodsproductsImgShowCommandHandler(IBaseRepository<ImgInfo> imgRepository)
        {
            _ImgRepository = imgRepository;
        }
        public Task<APIResult<List<ImgInfo>>> Handle(GoodsproductsImgShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ImgInfo>> result=new APIResult<List<ImgInfo>>();
            try
            {
                var list = _ImgRepository.GetAll().Where(x => x.GoodsId == request.Id).ToList();
                result.Code = ApiEnum.Success;
                result.Msg = "产品检验报告显示成功";
                result.Data= list;
                return Task.FromResult(result);
            }
            catch (Exception)
            {
                result.Code = ApiEnum.Fail;
                result.Msg = "产品检验报告显示失败";
                return Task.FromResult(result);
                throw;
            }
        }
    }
}
